/*
 * @Author: xuetao 3168581151@qq.com
 * @Date: 2025-01-06
 * @LastEditors: xuetao 3168581151@qq.com
 * @LastEditTime: 2025-02-07
 * @Description: 带文本的分隔符组件
 */
import 'package:flutter/material.dart';

// 自定义分割线组件
class DividerWithText extends StatelessWidget {
  final String? text; // 分割线文本内容
  final Color backgroundColor; // 背景颜色
  final double height; // 高度

  // 构造函数
  const DividerWithText({
    Key? key,
    this.text,
    this.backgroundColor = const Color.fromARGB(255, 237, 237, 237), // 默认背景颜色
    this.height = 20, // 默认高度
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final padding = (height - 12) / 2; // 计算上下内边距

    return Container(
      color: backgroundColor, // 背景颜色
      padding: EdgeInsets.symmetric(vertical: padding), // 添加上下间距
      child: text != null
          ? Row(
              children: [
                Padding(
                  padding: const EdgeInsets.only(left: 20.0), // 左侧间距
                  child: Text(
                    text!,
                    style: const TextStyle(
                      fontSize: 12,
                      fontWeight: FontWeight.w500, // 字体加粗
                    ),
                  ),
                ),
              ],
            )
          : null, // 如果没有传入文本则不显示 Row
    );
  }
}

// 普通分割线组件,(函数式组件)
Widget buildDivider(
    {Color color = const Color.fromARGB(255, 237, 237, 237),
    double thickness = 1.0,
    double indent = 66.0,
    double endIndent = 20.0,
    double height = 1}) {
  return Divider(
    color: color,
    thickness: thickness,
    height: height,
    indent: indent,
    endIndent: endIndent,
  );
}
